//
//    BankInfo.swift
//
//    Create by 徐挺 陈 on 30/3/2018
//    Copyright © 2018. All rights reserved.
//    Model file generated using JSONExport: https://github.com/Ahmed-Ali/JSONExport

import Foundation
import SwiftyJSON
import PromiseKit


class BankInfo : NSObject, NSCoding{
    
    var bankCode : String!
    var bankId : Int!
    var bankName : String!
    var contact : String!
    var contactName : String!
    var subBankName : String!
    
    
    /**
     * Instantiate the instance using the passed json values to set the properties values
     */
    init(fromJson json: JSON!){
        if json.isEmpty{
            return
        }
        bankCode = json["bankCode"].stringValue
        bankId = json["bankId"].intValue
        bankName = json["bankName"].stringValue
        contact = json["contact"].stringValue
        contactName = json["contactName"].stringValue
        subBankName = json["subBankName"].stringValue
    }
    
    /**
     * Returns all the available property values in the form of [String:Any] object where the key is the approperiate json key and the value is the value of the corresponding property
     */
    func toDictionary() -> [String:Any]
    {
        var dictionary = [String:Any]()
        if bankCode != nil{
            dictionary["bankCode"] = bankCode
        }
        if bankId != nil{
            dictionary["bankId"] = bankId
        }
        if bankName != nil{
            dictionary["bankName"] = bankName
        }
        if contact != nil{
            dictionary["contact"] = contact
        }
        if contactName != nil{
            dictionary["contactName"] = contactName
        }
        if subBankName != nil{
            dictionary["subBankName"] = subBankName
        }
        return dictionary
    }
    
    /**
     * NSCoding required initializer.
     * Fills the data from the passed decoder
     */
    @objc required init(coder aDecoder: NSCoder)
    {
        bankCode = aDecoder.decodeObject(forKey: "bankCode") as? String
        bankId = aDecoder.decodeObject(forKey: "bankId") as? Int
        bankName = aDecoder.decodeObject(forKey: "bankName") as? String
        contact = aDecoder.decodeObject(forKey: "contact") as? String
        contactName = aDecoder.decodeObject(forKey: "contactName") as? String
        subBankName = aDecoder.decodeObject(forKey: "subBankName") as? String
        
    }
    
    /**
     * NSCoding required method.
     * Encodes mode properties into the decoder
     */
    func encode(with aCoder: NSCoder)
    {
        if bankCode != nil{
            aCoder.encode(bankCode, forKey: "bankCode")
        }
        if bankId != nil{
            aCoder.encode(bankId, forKey: "bankId")
        }
        if bankName != nil{
            aCoder.encode(bankName, forKey: "bankName")
        }
        if contact != nil{
            aCoder.encode(contact, forKey: "contact")
        }
        if contactName != nil{
            aCoder.encode(contactName, forKey: "contactName")
        }
        if subBankName != nil{
            aCoder.encode(subBankName, forKey: "subBankName")
        }
        
    }
    
    func save() -> Promise<JSON> {
        let dic = self.toDictionary()
        let request = RequestData(path: "User/SaveUserBankInfo", param: dic)
        return netRequest(request)
    }
}
